# -*- coding: utf-8 -*-
"""
@Time    : 2022/11/5 23:57
@Author  : JackXia
@Email   : 915624876@qq.com
@QQ      : 915624876
@File    : 20. 有效的括号.py
@Software: PyCharm
"""


class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        list1 = []
        reflect = {
            ")": "(",
            "}": "{",
            "]": "[",
        }
        for i in s:
            if i in {"(", "{", "["}:
                list1.append(i)
            else:
                if not len(list1):
                    return False
                else:
                    if list1.pop() != reflect[i]:
                        return False
        return not len(list1)

if __name__ == '__main__':
    s = "("
    print(Solution().isValid(s))